package views
{
	import inerface.IScenicShopDetailPanel;
	
	import main.ClientConstants;
	import main.ViewSubBase;
	
	import panel.scenicShop.ScenicShopDetailPanel;
	
	import struct.ScenicShop;
	
	public class ScenicShopDetailView extends ViewSubBase
	{
		private var _panel:IScenicShopDetailPanel;
		private var currentShopId:int = 0;
		
		public function ScenicShopDetailView()
		{
		}
		
		public function set shopId(id:int):void
		{
			currentShopId = id;
		}
		
		public override function show():void
		{
			render();
		}
		
		protected override function render():void
		{
			if(_panel == null){
				_panel = new ScenicShopDetailPanel;
				_panel.init(view.layout.stage,view.resourceLoader,view.lang,view.uri);
				_panel.comment = commentThis;
				_panel.onAddPath = addToPath;
				_panel.onShowLocation = showLocation;
				
				var shopObj:ScenicShop;
				for(var i:int = 0;i < data.viewSpot.shopList.length;i++){
					if(data.viewSpot.shopList[i]["id"] == currentShopId){
						shopObj = data.viewSpot.shopList[i];
						break;
					}
				}
				
				_panel.changeData(shopObj);
			}
			this.addView(_panel);
		}
		
		
		private function addToPath(obj:*):void
		{
			var bool:Boolean = data.choosePath.element(obj);
			if(bool == true){
				view.alert.showAlert("添加成功","确定");
				return;
			}else{
				view.alert.showAlert("当前编辑路线中已添加该地点","返回");
				return;
			}
		}
		
		public override function close():void
		{
			view.layout.closeView(this);
		}
		
		public override function clear():void
		{
			if(_panel){
				_panel.clear();
				_panel = null;
			}
		}
		
		private function commentThis():void
		{
			view.comment.shopType = ClientConstants.COMMENT_TYPE_SCENIC_SHOP;
			view.comment.info = currentShopId;
			view.comment.show();
		}
		
		private function showLocation(obj:*):void
		{
			view.showLocation.objInfo = obj;
			view.showLocation.show();
		}
	}
}